<script setup>
/**
 * @name 图文剪辑列表
 */

import { computed, onMounted, reactive, ref } from 'vue';
import {
    SearchOutlined,
} from "@ant-design/icons-vue";
import TopHeader from '@/views/shotstack/components/TopHeader/index.vue'
const TopHeaderRef = ref()
import request from "@/common/utils/request";

import { useStore } from "vuex";
const store = useStore();

import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();

// 权限数据
const clipRole = computed(() => store.state.user?.clipRole || [])

const state = reactive({
    timer: [],
    list: []
})

const getFormState = () =>{
  return {
    title: '',
  page: 1,
  pageSize: 20,
  total: 0,
  }
}

const formState = reactive(getFormState())

const PageChange = (page, pageSize) => {
  console.log(page,pageSize);
  getListData()
}

// 头部按钮点击回调
const btnClick = (item) => {
    console.log(item,'点击的按钮');
    router.push({
        name:'GraphicTextCut'
    })
}

// 查看详情
const ViewPoiDetail = (item) => {
    router.push({
      name: 'GraphicTextCut',
      query: {
        detailId: item.id
      }
    })
}

const clearHandle = () =>{
  Object.assign(formState, getFormState())
  state.timer = []
  getListData()
}

// 获取列表数据
const getListData = async () => {
  console.log(state.timer,'选择的日期');
  
  const params = {
    ...formState,
    start_time: state.timer?.[0],
    end_time: state.timer?.[1],
  }
  const res = await request.get("/work_ai", "/user/image/clip/list", params)
  console.log(res,'列表详情??');

  state.list = res.result.data
  formState.total = res.result.total
}

onMounted(() => {
  getListData()
})

    
</script>

<template>
    <div class="GraphicTextMontage">
        <!-- 头部 -->
        <TopHeader ref="TopHeaderRef" 
        :config="{
        title: '图文剪辑',
        dec:'智能文案与图集无缝配合，为你的内容创作省时省力，效率倍增！'
        }"
        :btnList="[
            {
                text:'创建图文剪辑', // 按钮文本
                type:'primary',  // 按钮类型
                role:'' // 按钮鉴权key
            }
        ]" 
        @btnClick="btnClick"
        />


<div class="smart-clip-content">
    <!-- 头部搜索条件 -->
        <div class="clip-content-search">
          <div class="smart-clip-header-title">图文项目</div>
          <div class="smart-clip-content-serch">
            <div class="content-serch-item">
              <a-input placeholder="请输入图文项目名" allowClear v-model:value="formState.title" style="width: 100%">
                <template #prefix>
                  <SearchOutlined />
                </template>
              </a-input>
            </div>
            <div class="content-serch-item">
              <a-range-picker valueFormat="YYYY-MM-DD" style="width: 100%" v-model:value="state.timer" />
            </div>
            <div class="content-serch-item">
              <a-button class="search-btn" type="dashed" @click="clearHandle" style="margin-right: 10px">清空</a-button>
              <a-button type="primary" class="search-btn" @click="getListData">搜索</a-button>
            </div>
          </div>
        </div>

        <template  v-if="state.list.length">
          <div class="smart-clip-content-List">
              <div class="smart-clip-content-item" v-for="(item, index) in state.list" 
              :key="item.id">
                <!-- 置灰遮罩层 -->
                <!-- <a-popover>
                  <template #content> 项目剪辑中 </template>
                  <div class="smart-clip-content-item-mask" v-if="item.status == 1"></div>
                </a-popover> -->
  
                <div class="smart-clip-content-itemInfo" @click="ViewPoiDetail(item)">
                  <div class="smart-clip-content-itemInfo_lf">
                    <img :src="item.resource_data[0].images[0].url" alt=""
                      style="width: 100%; height: 100%" />
                  </div>
                  <div class="smart-clip-content-itemInfo_rg">
                    <!-- 图文名称 -->
                    <div class="itemInfo_rg-title">
                      <a-tooltip v-if="item.title.trim().length > 16">
                        <template #title>
                          <div style="max-width: 200px">
                            {{ item.title }}
                          </div>
                        </template>
                        {{ item.title.trim().substring(0, 16) + "..." }}
                      </a-tooltip>
                      <div v-else>
                        {{ item.title }}
                      </div>
                    </div>
                    <div class="itemInfo_rg-desc">
                      <!-- 创建时间 -->
                      <div class="info_rg_desc_item">
                        创建时间：
                        <a-tooltip>
                          <template #title v-if="item?.created_at?.trim().length > 10">{{ item.created_at }}</template>
                          {{ item.created_at }}
                        </a-tooltip>
                      </div>
                      <!-- 更新时间 -->
                      <div class="info_rg_desc_item">
                        更新时间：
                        <a-tooltip>
                          <template #title v-if="item.updated_at.trim().length > 10">{{ item.updated_at }}</template>
                          {{ item.updated_at }}
                        </a-tooltip>
                      </div>
  
                      <template v-if="false">
                        <!-- 剪辑状态,剪辑中才显示 -->
                        <div class="info_rg_desc_item" v-if="item.status == 1">
                          <div class="info_rg_desc_item_status">
                            剪辑中：
                            <!-- 进度条 -->
                            <div class="progress_item">
                              <a-progress :percent="100" :showInfo="false" type="line" size="small" :stroke-color="{
                                '0%': '#108ee9',
                                '100%': '#87d068',
                              }" status="active" />
                            </div>
                          </div>
                        </div>
                        <!-- 视频预览状态,生成中才显示 -->
                        <div class="info_rg_desc_item" v-if="item.statusMixedCut == 2">
                          <div class="info_rg_desc_item_status" style="line-height:1.5">
                            当前状态：
                            <a-tag color="processing"
                              style="border-radius: 5px; font-size: 10px;line-height:1.5;padding-top:0;padding-bottom:0">
                              <template #icon>
                                <sync-outlined :spin="true" />
                              </template>
                              预览视频生成中
                            </a-tag>
                          </div>
                        </div>
                      </template>
                    </div>
                    <div class="info-rg-count">
                      <!-- <a-tooltip>
                        <template #title v-if="item.material_num >= 100">
                          素材数量：{{ item?.material_num }}</template>
                        <span> 素材数量：{{ item?.material_num }}</span>
                      </a-tooltip> -->
                      <a-tooltip>
                        <template #title v-if="item?.scene_name?.length >= 100">
                          镜头数量：{{ item?.resource_data?.length }}
                        </template>
                        <span> 镜头数量：{{ item?.resource_data?.length }}</span>
                      </a-tooltip>
                    </div>
                  </div>
                </div>
                <div class="smart-clip-content-btn" >
                  <div class="tag_box">
                    <a-tag class="tag_item" style="margin-right: 10px"  @click="ViewPoiDetail(item)" 
                     >编辑</a-tag>
                  </div>
                </div>
              </div>
            </div>
            <div class="smart_clip_content_pagination">
            <a-pagination class="pagination" :total="formState.total" v-model:current="formState.page" v-model:pageSize="formState.pageSize" show-less-items
              @change="PageChange" />
          </div>
        </template>
          <div class="empty" v-else>
            <a-empty />
          </div>
      </div>

    </div>
</template>


<style lang="less" scoped>
@minw:0px;

.GraphicTextMontage{
    padding: 14px;

    .smart-clip-content {
    margin-top: 24px;
    min-width: @minw;

      // 搜索
  .clip-content-search {
    min-width: @minw;
    display: flex;

    .smart-clip-header-title {
      margin-right: 20px;
      font-size: 20px;
      color: #1c1f23;
      font-weight: 600;
    }

    .smart-clip-content-serch {
      flex: 1;
      display: flex;
      justify-content: end;

      .content-serch-item {
        &:nth-child(1) {
          width: 20%;
        }

        &:nth-child(2) {
          width: 20%;
          margin: 0 10px;
        }
      }
    }

    .search-btn {
      border-radius: 5px;
    }
  }

  // 空状态
  .empty {
    height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 30px;
  }

  // 图文剪辑列表
.smart-clip-content-List {
  margin-top: 30px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-gap: 16px;

  .smart-clip-content-item {
  width: 100%;
  // min-width: 335px;
  height: 100%;
  border: 1px solid #eaedf1;
  border-radius: 4px;
  background-color: #fff;
  transition: all 0.3s;
  position: relative;

  &:hover {
    // border-color: #2878FF;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  }

  // 置灰遮罩
  .smart-clip-content-item-mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.3;
    z-index: 10;
    cursor: not-allowed;
    border: 1px solid #eaedf1;
    transition: all 0.3s;

    &:hover {
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }
  }

  .smart-clip-content-itemInfo {
  display: flex;
  padding: 10px;
  cursor: pointer;

  // height: 140px;
  .smart-clip-content-itemInfo_lf {
    height: 100%;
    border: 1px solid #eaedf1;
    width: 100px;
    min-width: 100px;
    margin-right: 3%;
    height: 140px;
    display: flex;
    align-items: center;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }

  .smart-clip-content-itemInfo_rg {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 140px;
    padding-left: 5px;
    // overflow-y: hidden;
    overflow: hidden;

    .itemInfo_rg-title {
      font-size: 14px;
      margin-bottom: 4px;
      color: #0c0d0e;
      /* 溢出内容隐藏 */
      overflow: hidden;
      /* 文本溢出显示省略号 */
      text-overflow: ellipsis;
      /* 文本在一行显示 */
      white-space: nowrap;
    }

    .itemInfo_rg-desc {
      overflow-x: hidden;
      overflow-y: auto;
      padding-right: 4px;
      flex: 1;

      &:hover {
        &::-webkit-scrollbar {
          display: block;
        }

        padding-right: 0;
      }

      height: 100%;

      &::-webkit-scrollbar {
        width: 4px;
        /* 滚动条的宽度 */
        height: 10px;
        /* 滚动条的高度，垂直滚动条可能用得上 */
        display: none;
      }

      &::-webkit-scrollbar-thumb {
        background: #888;
        /* 滑块的背景颜色 */
        border-radius: 10px;
        /* 滑块的圆角 */
      }

      .info_rg_desc_item {
        color: #737a87;
        font-size: 11px;
        /* 溢出内容隐藏 */
        overflow-x: hidden;
        /* 文本溢出显示省略号 */
        text-overflow: ellipsis;
        /* 文本在一行显示 */
        white-space: nowrap;
        margin-top: 5px;

        // 剪辑状��
        .info_rg_desc_item_status {
          display: flex;

          .progress_item {
            width: 70%;
          }
        }
      }
    }

    // 底部数量统计
    .info-rg-count {
      display: flex;
      // justify-content: space-between;
      font-size: 10px;
      align-items: center;
      font-weight: 500;

      span {
        color: #737a87;
        width: 70px;
        background: #eaedf1;
        text-overflow: ellipsis;
        white-space: nowrap;
        border-radius: 5px;
        padding: 0 3px;
        overflow-x: hidden;
        text-align: center;
        margin-right: 10px;
      }
    }
  }
}

.smart-clip-content-btn {
  height: 40px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid #eaedf1;

  :deep(.ss-popover-title) {
    display: none;
  }

  .del_btn {
    cursor: pointer;
    display: inline-block;
    width: 50px;
    text-align: center;

    &:hover {
      color: #ff4d4f;
    }
  }

  .info-rg-more {
    cursor: pointer;
    padding: 1px 6px;
    border-radius: 3px;
    overflow: hidden;

    &:hover {
      background-color: #f0f1f2;
    }
  }

  .tag_box {
    .tag_item {
      padding: 1px 12px;
      border-radius: 3px;
      cursor: pointer;

      &:hover {
        border-color: #2878ff;
      }
    }
  }
}
}
}

.smart_clip_content_pagination{
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  .pagination{
  }
}


}

}
</style>